//
//  marketViewController.swift
//  股票框架
//
//  Created by 李小骥 on 2017/9/28.
//  Copyright © 2017年 李小骥. All rights reserved.
//

import UIKit
import SnapKit
import DZNEmptyDataSet
class MarketViewController: UITableViewController,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate  {
    var sseCompositeIndexLabel = UILabel()
    var szseComponentIndexLabel = UILabel()
    var smallAndMediumEnterpriseBoardIndexLabel = UILabel()
    var sseCompositeIndexNumberLabel = UILabel()
    var szseComponentIndexNumberLabel = UILabel()
    var smallAndMediumEnterpriseBoardIndexNumberLabel = UILabel()
    var sseCompositeIndexDropPercentNumberLabel = UILabel()
    var sseCompositeIndexIncreasePercentNumberLabel = UILabel()
    var szseComponentIndexDropPercentNumberLabel = UILabel()
    var szseComponentIndexIncreasePercentNumberLabel = UILabel()
    var smallAndMediumEnterpriseBoardIndexDropPercentNumberLabel = UILabel()
    var smallAndMediumEnterpriseBoardIndexIncreasePercentNumberLabel = UILabel()
    var gegumingchengLabel = UILabel()
    var xianjiaLabel = UILabel()
    var zhangfuLabel = UILabel()
    var zixuangu=Zixuangu(){
        didSet{
            tableView.reloadData()
        }
    }
    var timer:Timer!
   

    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print(zixuangu)
        self.view.backgroundColor = .Background
        tableView.dataSource = self
        tableView.delegate = self
        tableView.emptyDataSetSource = self
        tableView.emptyDataSetDelegate = self
        tableView.tableFooterView = UIView()
        tableView.frame = CGRect(x: 0, y: 64+130+45, width: SCREEN_WIDTH, height: SCREEN_HEIGHT-64-130-45)
        loadZixuangu()
        addViews()
        setTimer()
        setViews()
        addThreeLabels()
        setThreeLabels()
        addSearchStockButton()
        //空白 view 包含按钮
//        let emptyView = UIView(frame: CGRect(x: 0, y: MUTABLEVIEW_Y, width: SCREEN_WIDTH, height: MUTABLEVIEW_HEIGHT))
//        所有控件使用的坐标位置都是相当于父控件的位置，如果想把坐标位置给子控件用，需要先把坐标从相对于父控件转换为相对于自己，这样的坐标对于子控件来说恰好是相当于它的父控件
//        先把按钮的中心要从绝对的 self.view 转换到相对于它的父控件 emptyView 的位置
//        let searchStockCenterRelativeToEmptyView = emptyView.convert(emptyView.center, from: self.view)
//        let searchStock = UIButton(frame: CGRect(center: searchStockCenterRelativeToEmptyView, size: CGSize(width: 60, height: 60)))
//        searchStock.backgroundColor = .APP
//        emptyView.backgroundColor = .Drop
////        let point = emptyView.convert(emptyView.center, to: self.view)
//        emptyView.addSubview(searchStock)
//        searchStock.addTarget(self, action: #selector(jumptodetail), for: .touchUpInside)
//        self.view.addSubview(emptyView)
        
//        print(emptyView.bounds.height)
//        print(emptyView.frame.height)
//        print(emptyView.center)
//        print(searchStock.center)
//        print(searchStock.frame)
                // Do any additional setup after loading the view.
    }
    func setTimer(){
        weak var weakSelf:MarketViewController? = self
        timer = Timer.scheduledTimer(withTimeInterval: requestTimeInterval, repeats: true, block: { (_) in
            weakSelf?.loadZixuanguMarketData()
        })
    }
    func loadZixuanguMarketData(){
        weak var weakSelf:MarketViewController? = self
        Utils.AlamofireAsynchronousGETZixuanguMarketData { (result) in
            weakSelf?.sseCompositeIndexNumberLabel.text = result![0].nowPrice
            weakSelf?.szseComponentIndexNumberLabel.text = result![1].nowPrice
            weakSelf?.smallAndMediumEnterpriseBoardIndexNumberLabel.text = result![2].nowPrice
            weakSelf?.sseCompositeIndexDropPercentNumberLabel.text = result![0].diff_money
            weakSelf?.szseComponentIndexDropPercentNumberLabel.text = result![1].diff_money
            weakSelf?.smallAndMediumEnterpriseBoardIndexDropPercentNumberLabel.text = result![2].diff_money
            weakSelf?.sseCompositeIndexIncreasePercentNumberLabel.text = result![0].diff_rate
            weakSelf?.szseComponentIndexIncreasePercentNumberLabel.text = result![1].diff_rate
            weakSelf?.smallAndMediumEnterpriseBoardIndexIncreasePercentNumberLabel.text = result![2].diff_rate
            let sseCompositeIndexColor = (result![0].diff_rate.hasPrefix("-")) ? UIColor.Drop : UIColor.APP
            let szseComponentIndexIndexColor = (result![1].diff_money.hasPrefix("-")) ? UIColor.Drop : UIColor.APP
            let smallAndMediumEnterpriseBoardIndexIndexIndexColor = (result![2].diff_money.hasPrefix("-")) ? UIColor.Drop : UIColor.APP
            weakSelf?.sseCompositeIndexLabel.textColor = sseCompositeIndexColor
            weakSelf?.sseCompositeIndexNumberLabel.textColor = sseCompositeIndexColor
            weakSelf?.sseCompositeIndexDropPercentNumberLabel.textColor = sseCompositeIndexColor
            weakSelf?.sseCompositeIndexIncreasePercentNumberLabel.textColor = sseCompositeIndexColor
            weakSelf?.szseComponentIndexLabel.textColor = szseComponentIndexIndexColor
            weakSelf?.szseComponentIndexNumberLabel.textColor = szseComponentIndexIndexColor
            weakSelf?.szseComponentIndexDropPercentNumberLabel.textColor = szseComponentIndexIndexColor
            weakSelf?.szseComponentIndexIncreasePercentNumberLabel.textColor = szseComponentIndexIndexColor
            weakSelf?.smallAndMediumEnterpriseBoardIndexLabel.textColor = smallAndMediumEnterpriseBoardIndexIndexIndexColor
            weakSelf?.smallAndMediumEnterpriseBoardIndexNumberLabel.textColor = smallAndMediumEnterpriseBoardIndexIndexIndexColor
            weakSelf?.smallAndMediumEnterpriseBoardIndexDropPercentNumberLabel.textColor = smallAndMediumEnterpriseBoardIndexIndexIndexColor
            weakSelf?.smallAndMediumEnterpriseBoardIndexIncreasePercentNumberLabel.textColor = smallAndMediumEnterpriseBoardIndexIndexIndexColor
        }//30s 一次
    }
    func addSearchStockButton(){
        let rightButton = UIBarButtonItem(image: UIImage(named:"searchButton"), style: .plain, target: self, action: #selector(jumptodetail))
        rightButton.tintColor = .white
        navigationItem.rightBarButtonItem = rightButton
    }
    func loadZixuangu(){
        if(!zixuangu.codes.isEmpty){
            weak var weakSelf:MarketViewController? = self
            let callBack:(([ZixuanguData]?)->(Void)) = { result in
                //            如果数组里还没有，就加入数组
                guard let re = result,!re.isEmpty else{return }
                for data in re{
                    let gupiao = Gupiao(name: data.name, code: data.code, currentPrice: data.nowPrice, zhangfu: data.diff_rate)
                    weakSelf?.zixuangu.gupiaos.append(gupiao)
                }
                weakSelf?.tableView.reloadData()
                
            }
            Utils.AlamofireAsynchronousGETZixuanguData(codes: zixuangu.codes, callBack: callBack)
        }
    }
    @objc func jumptodetail(){

        let searchStockViewController = SearchStockViewController()//SearchStockViewController()
        searchStockViewController.marketViewControllerDelegate = self
        searchStockViewController.navigationItem.title = "搜索股票"
        let searchStockViewNavigationController = UINavigationController(rootViewController: searchStockViewController)
//        searchStockViewNavigationController.navigationBar.setBackgroundColor(.APP)
        searchStockViewNavigationController.navigationBar.titleTextAttributes = (naviBarTitleAttributes as! [NSAttributedStringKey : Any])
//        防止重复弹出
        let viewController = UIApplication.shared.keyWindow?.rootViewController
        if let isNavigationController = viewController?.presentedViewController?.isKind(of: UINavigationController.self){
            if(isNavigationController == true){
            let navigation = viewController?.presentedViewController as! UINavigationController
            if(navigation.topViewController?.isKind(of: SearchStockViewController.self))!{
                return
            }
        }
        }
        if((viewController?.presentedViewController) != nil){
            viewController?.presentedViewController?.dismiss(animated: false, completion: {
                viewController?.present(searchStockViewNavigationController, animated: true, completion: nil)
            })
        }else{
            viewController?.present(searchStockViewNavigationController, animated: true, completion: nil)
        }
        
        
        

//        navigationController?.pushViewController(searchStockViewController, animated: true)
//        present(searchStockViewNavigationController, animated: true, completion: nil)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()


        // Dispose of any resources that can be recreated.
    }
    func addViews(){
        self.sseCompositeIndexLabel = UILabel(x: SSECOMPOSITEINDEXLABEL_X, y: SSECOMPOSITEINDEXLABEL_Y, height: SSECOMPOSITEINDEXLABEL_HEIGHT, text: "上证指数", font:SSECOMPOSITEINDEXLABEL_FONT , aliment: .center, color: .APP)
        self.view.addSubview(sseCompositeIndexLabel)
        
        self.szseComponentIndexLabel = UILabel(x: SZSECOMPONENTINDEXLABEL_X, y: SZSECOMPONENTINDEXLABEL_Y, height: SZSECOMPONENTINDEXLABEL_HEIGHT, text: "深证指数", font: SZSECOMPONENTINDEXLABEL_FONT, aliment: .center, color: .APP)
        self.view.addSubview(szseComponentIndexLabel)
        
        self.smallAndMediumEnterpriseBoardIndexLabel = UILabel(x: SMALLANDMEDIUMENTERPRISEBOARDINDEXLABEL_X, y: SMALLANDMEDIUMENTERPRISEBOARDINDEXLABEL_Y, height: SMALLANDMEDIUMENTERPRISEBOARDINDEXLABEL_HEIGHT, text: "中小板指", font: SMALLANDMEDIUMENTERPRISEBOARDINDEXLABEL_FONT, aliment: .center, color: .APP)
        self.view.addSubview(smallAndMediumEnterpriseBoardIndexLabel)
        
        self.sseCompositeIndexNumberLabel = UILabel(x: SSECOMPOSITEINDEXNUMBERLABEL_X, y: SSECOMPOSITEINDEXNUMBERLABEL_Y, height: SSECOMPOSITEINDEXNUMBERLABEL_HEIGHT, text: "3222.05", font: SSECOMPOSITEINDEXNUMBERLABEL_FONT, aliment: .center, color: .APP)
        self.view.addSubview(sseCompositeIndexNumberLabel)
        
        self.szseComponentIndexNumberLabel = UILabel(x: SZSECOMPONENTINDEXNUMBERLABEL_X, y: SZSECOMPONENTINDEXNUMBERLABEL_Y, height: SZSECOMPONENTINDEXNUMBERLABEL_HEIGHT, text: "250.365", font: SZSECOMPONENTINDEXNUMBERLABEL_FONT, aliment: .center, color: .APP)
        self.view.addSubview(szseComponentIndexNumberLabel)
        
        self.smallAndMediumEnterpriseBoardIndexNumberLabel = UILabel(x: SMALLANDMEDIUMENTERPRISEBOARDINDEXNUMBERLABEL_X, y: SMALLANDMEDIUMENTERPRISEBOARDINDEXNUMBERLABEL_Y, height: SMALLANDMEDIUMENTERPRISEBOARDINDEXNUMBERLABEL_HEIGHT, text: "1559.86", font: SMALLANDMEDIUMENTERPRISEBOARDINDEXNUMBERLABEL_FONT, aliment: .center, color: .APP)
        self.view.addSubview(smallAndMediumEnterpriseBoardIndexNumberLabel)
        
        self.sseCompositeIndexDropPercentNumberLabel = UILabel(x: SSECOMPOSITEINDEXDROPPERCENTNUMBERLABEL_X, y: SSECOMPOSITEINDEXDROPPERCENTNUMBERLABEL_Y, height: SSECOMPOSITEINDEXDROPPERCENTNUMBERLABEL_HEIGHT, text: "-2.5%", font: SSECOMPOSITEINDEXDROPPERCENTNUMBERLABEL_FONT, aliment: .center, color: .Drop)
        self.view.addSubview(sseCompositeIndexDropPercentNumberLabel)
        
        self.sseCompositeIndexIncreasePercentNumberLabel = UILabel(x: SSECOMPOSITEINDEXINCREASEPERCENTNUMBERLABEL_X, y: SSECOMPOSITEINDEXINCREASEPERCENTNUMBERLABEL_Y, height: SSECOMPOSITEINDEXINCREASEPERCENTNUMBERLABEL_HEIGHT, text: "+2.5%", font: SSECOMPOSITEINDEXINCREASEPERCENTNUMBERLABEL_FONT, aliment: .center, color: .APP)
        self.view.addSubview(sseCompositeIndexIncreasePercentNumberLabel)
        
        self.szseComponentIndexDropPercentNumberLabel = UILabel(x: SZSECOMPONENTINDEXDROPPERCENTNUMBERLABEL_X, y: SZSECOMPONENTINDEXDROPPERCENTNUMBERLABEL_Y, height: SZSECOMPONENTINDEXDROPPERCENTNUMBERLABEL_HEIGHT, text: "-2.5%", font: SZSECOMPONENTINDEXDROPPERCENTNUMBERLABEL_FONT, aliment: .center, color: .Drop)
        self.view.addSubview(szseComponentIndexDropPercentNumberLabel)
        
        self.szseComponentIndexIncreasePercentNumberLabel = UILabel(x: SZSECOMPONENTINDEXINCREASEPERCENTNUMBERLABEL_X, y: SZSECOMPONENTINDEXINCREASEPERCENTNUMBERLABEL_Y, height: SZSECOMPONENTINDEXINCREASEPERCENTNUMBERLABEL_HEIGHT, text: "+2.5%", font: SZSECOMPONENTINDEXINCREASEPERCENTNUMBERLABEL_FONT, aliment: .center, color: .APP)
        self.view.addSubview(szseComponentIndexIncreasePercentNumberLabel)
        
        self.smallAndMediumEnterpriseBoardIndexDropPercentNumberLabel = UILabel(x: SMALLANDMEDIUMENTERPRISEBOARDINDEXDROPPERCENTNUMBERLABEL_X, y: SMALLANDMEDIUMENTERPRISEBOARDINDEXDROPPERCENTNUMBERLABEL_Y, height: SMALLANDMEDIUMENTERPRISEBOARDINDEXDROPPERCENTNUMBERLABEL_HEIGHT, text: "-2.5%", font: SMALLANDMEDIUMENTERPRISEBOARDINDEXDROPPERCENTNUMBERLABEL_FONT, aliment: .center, color: .Drop)
        self.view.addSubview(smallAndMediumEnterpriseBoardIndexDropPercentNumberLabel)
        
        self.smallAndMediumEnterpriseBoardIndexIncreasePercentNumberLabel = UILabel(x: SMALLANDMEDIUMENTERPRISEBOARDINDEXINCREASEPERCENTNUMBERLABEL_X, y: SMALLANDMEDIUMENTERPRISEBOARDINDEXINCREASEPERCENTNUMBERLABEL_Y, height: SMALLANDMEDIUMENTERPRISEBOARDINDEXINCREASEPERCENTNUMBERLABEL_HEIGHT, text: "+2.5%", font: SMALLANDMEDIUMENTERPRISEBOARDINDEXINCREASEPERCENTNUMBERLABEL_FONT, aliment: .center, color: .APP)
        self.view.addSubview(smallAndMediumEnterpriseBoardIndexIncreasePercentNumberLabel)

    }
    func setViews(){
        sseCompositeIndexLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(SCREEN_WIDTH/6)
            make.top.equalTo(26)
//            make.left.equalTo(35)
            make.height.equalTo(20)
            make.width.equalTo(80)
        }
        szseComponentIndexLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(SCREEN_WIDTH/2)
            make.top.equalTo(sseCompositeIndexLabel.snp.top)
//            make.left.equalTo(sseCompositeIndexLabel.snp.right).offset(40)
            make.height.equalTo(sseCompositeIndexLabel.snp.height)
            make.width.equalTo(sseCompositeIndexLabel.snp.width)
        }
        smallAndMediumEnterpriseBoardIndexLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(SCREEN_WIDTH/6*5)
            make.top.equalTo(sseCompositeIndexLabel.snp.top)
//            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(sseCompositeIndexLabel.snp.height)
//            make.right.equalTo(-35)
            make.width.equalTo(sseCompositeIndexLabel.snp.width)
        }
        sseCompositeIndexNumberLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(sseCompositeIndexLabel.snp.centerX)
            make.top.equalTo(sseCompositeIndexLabel.snp.bottom).offset(20)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(15)
            //            make.right.equalTo(-35)
            make.width.equalTo(sseCompositeIndexLabel.snp.width)
        }
        szseComponentIndexNumberLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(szseComponentIndexLabel.snp.centerX)
            make.top.equalTo(sseCompositeIndexNumberLabel.snp.top)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(sseCompositeIndexNumberLabel.snp.height)
            //            make.right.equalTo(-35)
            make.width.equalTo(sseCompositeIndexNumberLabel.snp.width)
        }
        smallAndMediumEnterpriseBoardIndexNumberLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(smallAndMediumEnterpriseBoardIndexLabel.snp.centerX)
            make.top.equalTo(sseCompositeIndexNumberLabel.snp.top)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(sseCompositeIndexNumberLabel.snp.height)
            //            make.right.equalTo(-35)
            make.width.equalTo(sseCompositeIndexNumberLabel.snp.width)
        }
        sseCompositeIndexDropPercentNumberLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(SCREEN_WIDTH/12)
            make.top.equalTo(sseCompositeIndexNumberLabel.snp.bottom).offset(20)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(15)
            //            make.right.equalTo(-35)
            make.width.equalTo(50)
        }
        sseCompositeIndexIncreasePercentNumberLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(SCREEN_WIDTH/12*3)
            make.top.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.top)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.height)
            //            make.right.equalTo(-35)
            make.width.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.width)
        }
        szseComponentIndexDropPercentNumberLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(SCREEN_WIDTH/12*5)
            make.top.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.top)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.height)
            //            make.right.equalTo(-35)
            make.width.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.width)
        }
        szseComponentIndexIncreasePercentNumberLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(SCREEN_WIDTH/12*7)
            make.top.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.top)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.height)
            //            make.right.equalTo(-35)
            make.width.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.width)
        }
        smallAndMediumEnterpriseBoardIndexDropPercentNumberLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(SCREEN_WIDTH/12*9)
            make.top.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.top)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.height)
            //            make.right.equalTo(-35)
            make.width.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.width)
        }
        smallAndMediumEnterpriseBoardIndexIncreasePercentNumberLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(SCREEN_WIDTH/12*11)
            make.top.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.top)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.height)
            //            make.right.equalTo(-35)
            make.width.equalTo(sseCompositeIndexDropPercentNumberLabel.snp.width)
        }
    }
    func addThreeLabels(){
        view.addSubview(gegumingchengLabel)
        view.addSubview(xianjiaLabel)
        view.addSubview(zhangfuLabel)
        gegumingchengLabel.text = "个股名称"
        gegumingchengLabel.tintColor = .ThinLine
        gegumingchengLabel.textAlignment = .center
        gegumingchengLabel.snp.makeConstraints { (make) -> Void in
            //            下面的65是影响页面整体布局的高度，原因不明，比较关键，适配的时候写成变量，根据设备型号不同来变化
            make.top.equalTo(64+65)
            make.left.equalTo(0)
            make.right.equalTo(xianjiaLabel.snp.left)
            make.width.equalTo(xianjiaLabel.snp.width)
            make.height.equalTo(30)
        }
        xianjiaLabel.text = "现价"
        xianjiaLabel.tintColor = .ThinLine
        xianjiaLabel.textAlignment = .center
        xianjiaLabel.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(gegumingchengLabel.snp.top)
            make.right.equalTo(zhangfuLabel.snp.left)
            make.width.equalTo(zhangfuLabel.snp.width)
            make.height.equalTo(gegumingchengLabel.snp.height)
        }
        zhangfuLabel.text = "涨幅—"
        zhangfuLabel.textColor = .APP
        zhangfuLabel.tintColor = .ThinLine
        zhangfuLabel.textAlignment = .center
        zhangfuLabel.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(gegumingchengLabel.snp.top)
            make.right.equalTo(0)
            make.height.equalTo(gegumingchengLabel.snp.height)
        }
    }
    func setThreeLabels(){
        gegumingchengLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(sseCompositeIndexLabel.snp.centerX)
            make.top.equalTo(smallAndMediumEnterpriseBoardIndexDropPercentNumberLabel.snp.bottom).offset(26)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(45)
            //            make.right.equalTo(-35)
            make.width.equalTo(SCREEN_WIDTH/3)
        }
        gegumingchengLabel.backgroundColor = .ThinLine
        xianjiaLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(szseComponentIndexLabel.snp.centerX)
            make.top.equalTo(gegumingchengLabel.snp.top)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(gegumingchengLabel.snp.height)
            //            make.right.equalTo(-35)
            make.width.equalTo(gegumingchengLabel.snp.width)
        }
        xianjiaLabel.backgroundColor = .ThinLine
        zhangfuLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(smallAndMediumEnterpriseBoardIndexLabel.snp.centerX)
            make.top.equalTo(gegumingchengLabel.snp.top)
            //            make.left.equalTo(szseComponentIndexLabel.snp.right).offset(40)
            make.height.equalTo(gegumingchengLabel.snp.height)
            //            make.right.equalTo(-35)
            make.width.equalTo(gegumingchengLabel.snp.width)
        }
        zhangfuLabel.backgroundColor = .ThinLine
    }
    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return zixuangu.gupiaos.count
    }
    func buttonImage(forEmptyDataSet scrollView: UIScrollView, for state: UIControlState) -> UIImage? {
        return UIImage(named: "addButton")
    }
    
    func emptyDataSet(_ scrollView: UIScrollView, didTap button: UIButton) {
        jumptodetail()
    }
    //今后使用 customView 自定义空白视图
    func title(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
        let text = "搜索股票名称"
        let attributes = [NSAttributedStringKey.font:UIFont.boldSystemFont(ofSize: 15),NSAttributedStringKey.foregroundColor:UIColor.LabelFont]
        return NSAttributedString(string: text, attributes: attributes)
    }
    func description(forEmptyDataSet scrollView: UIScrollView) -> NSAttributedString? {
        let text = "添加自选股"
        let paragraph = NSMutableParagraphStyle()
        paragraph.lineBreakMode = .byWordWrapping
        paragraph.alignment = .center
        let attributes = [NSAttributedStringKey.font:UIFont.boldSystemFont(ofSize: 15),NSAttributedStringKey.foregroundColor:UIColor.LabelFont,NSAttributedStringKey.paragraphStyle:paragraph]
        return NSAttributedString(string: text, attributes: attributes)
    }
//    func buttonTitle(forEmptyDataSet scrollView: UIScrollView, for state: UIControlState) -> NSAttributedString? {
//        let paragraph = NSMutableParagraphStyle()
//        paragraph.lineBreakMode = .byWordWrapping
//        paragraph.alignment = .center
//        let attributes = [NSAttributedStringKey.font:UIFont.boldSystemFont(ofSize: 15),NSAttributedStringKey.foregroundColor:UIColor.LabelFont,NSAttributedStringKey.paragraphStyle:paragraph]
//        return NSAttributedString(string: "搜索股票名称/n添加自选股", attributes: attributes)
//    }
    
    
    
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let reuseIdentifier="zixuanguCell"
        var cell:ZixuanguTableViewCell? = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) as! ZixuanguTableViewCell
        if(cell==nil){
            cell=ZixuanguTableViewCell(style: .default, reuseIdentifier: reuseIdentifier)
        }
        cell?.nameLabel.text = zixuangu.gupiaos[indexPath.row].name
        cell?.codeLabel.text = zixuangu.gupiaos[indexPath.row].code
        cell?.currentPriceLabel.text = zixuangu.gupiaos[indexPath.row].currentPrice
        cell?.diffLabel.text = zixuangu.gupiaos[indexPath.row].zhangfu
        // Configure the cell...
        
        return cell!
    }
        override func viewDidDisappear(_ animated: Bool) {
            super.viewDidDisappear(animated)
            if(timer != nil){
                timer.invalidate()
            }
        }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
